package me.zhengjie.modules.utils.chat;

import cn.hutool.core.util.StrUtil;
import cn.hutool.json.JSONUtil;
import me.zhengjie.modules.utils.ApiConstant;
import me.zhengjie.utils.http.HttpUtils;

/**
 * 获取token
 *
 */
public class TokenUtil {
    private TokenUtil() {
    }

    public static String getToken(String appKey, String secretKey) {
        String s = HttpUtils.get(ApiConstant.getToken(appKey, secretKey));
        BaiDuToken bean = JSONUtil.toBean(s, BaiDuToken.class);
        if (StrUtil.isNotBlank(bean.getError())) {
            System.out.printf("获取token异常，err=%s", s);
        }
        return bean.getAccessToken();
    }
}